/*
 * @Author       : xh
 * @Date         : 2022-10-21 11:18:56
 * @LastEditors  : xh
 * @FileName     :
 */
/* 功能：传入一个DOM对象，判断是否点击除本身以外的其他dom上 */
import request from '@/utils/requests.js';
import { onMounted, onUnmounted, ref } from 'vue';
const useTable = (props) => {
  const loading = ref(true)
  const currentPage = ref(1)
  const currentSize = ref(10)
  const tableData = ref([])
  const total = ref(1)
  const { url, data } = props

  const getList = () => {
    request(url, {
      currentPage: currentPage.value,
      pageSize: currentSize.value,
      ...data
    }).then((res) => {
      tableData.value = res.data.list
      total.value = res.data.count
      loading.value = false
    })
  }
  const handleCurrentChange = (val) => {
    currentPage.value = val
    getList()
  }
  onMounted(() => {
    // document上加click监听事件
  });
  onUnmounted(() => {

  });
  return { getList, loading, currentPage, total, handleCurrentChange, tableData };
};

export default useTable;

